package home;

import java.io.*;

/**
 * Created by clq on 2019/4/17.
 */
public class guibing {
    static Comparable aux[] = null;
    public static void main(String[] args) throws FileNotFoundException {
        BufferedInputStream br = new BufferedInputStream(new FileInputStream(new File("")));
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br1 = new BufferedReader(isr);
       // String s = br1.readLine();
        Comparable arr[] = {123,2,12,234,2,12,2342,12,0,1};
        aux = new Comparable[arr.length];
        sort(arr);
        for(Comparable i : arr) {
            System.out.println(i);
        }
    }

    public static void sort(Comparable arr[]) {
        sort(arr, 0, arr.length-1);
    }

    public static void sort(Comparable arr[], int lo, int hi) {
        if(lo>=hi) {
            return;
        }
        int mid = lo+(hi-lo)/2;

        sort(arr, lo, mid);
        sort(arr, mid+1, hi);
        merge(arr, lo, mid, hi);
    }

    public static void merge(Comparable arr[], int lo, int mid, int hi) {
        int i=lo; int j=mid+1;
        for(int k=lo; k<=hi; k++) {
            aux[k] = arr[k];
        }
        for(int k=lo; k<=hi; k++) {
            if(i>mid) {
                arr[k] = aux[j++];
            }else if (j>hi) {
                arr[k] = aux[i++];
            }else if(less(aux[i], aux[j])) {
                arr[k] = aux[j++];
            }else {arr[k] = aux[i++];}
        }

    }

    public static boolean less(Comparable a, Comparable b) {
        return a.compareTo(b)<0 ? true : false;
    }


}
